package com.albaba.designpattern.singleton;

/**
 * @Description: 单例模式静态内部类
 * @Author zx
 * @Date 2025/2/18 17:26
 * @Version 1.0
 */
public class Singleton_005 {
    // 私有构造方法
    private Singleton_005() {
        if (SingletonHolder.instance != null) {
            throw new RuntimeException("不允许非法访问");
        }
    }


    // 创建静态内部类
    private static class SingletonHolder {
        // 在静态内部类中创建单例，在装载内部类的时候，才会创建单例对象
        private static final Singleton_005 instance = new Singleton_005();
    }

    public static Singleton_005 getInstance() {
        System.out.println("Singleton_005 getInstance");
        return SingletonHolder.instance;
    }
}
